<?PHP
session_cache_limiter('private, must-revalidate');
session_start();

//restrict page access
if(!isset($_SESSION['user']))
  {
    header('Location:index.php');
    exit;
  }

include("header.php");
include("std_dbs.php");

$userid = $_SESSION['userid'];
// get a list of pending movies
$query = "SELECT MOVID, MOVTITLE, DATEADDED, DATEACCEPTED, PENDSTATUS FROM MOVIES WHERE SUBMITTERID=$userid";

$stid = oci_parse($connect, $query);
if($stid == false)
  {
    $e = oci_error($connect);
    echo "ERROR: error parsing query to get the list of pending movies <br />";
    echo "MSG: ".$e['message']."<br />";
    exit;
  }

$ret = oci_execute($stid);
if($ret == false)
  {
//    $e = oci_error($stid);
//    echo "ERROR: error executing query to get the list of pending movies <br />";
//    echo "MSG: ".$e['message']."<br />";
//    exit;
                        $e = oci_error($stid);  // For oci_execute errors pass the statement handle
                        print htmlentities($e['message']);
                        print "\n<pre>\n";
                        print htmlentities($e['sqltext']);
                        echo $e['message'];
                        printf("\n%".($e['offset']+1)."s", "^");
                        print  "\n</pre>\n";
  }


//DISPLAY PENDING MOVIES

//set up divs
echo "<div id='content'><div class='post'><h1 class='title'><a href='#'>My Pending Movies</a></h1><br /><div class='entry'>";

//set up table
echo "<table width='90%'><tr><th>Movie ID</th><th>Title</th><th>Submit Date</th></tr>";
$count = 0;
while(($row = oci_fetch_array($stid, OCI_ASSOC)))
  {
	if($row['PENDSTATUS']=="1")
	{
    		// add row to the table
    		echo "<tr>";
    		echo "<td>".$row['MOVID']."</td>";
    		echo "<td>".$row['MOVTITLE']."</td>";
    		echo "<td>".$row['DATEADDED']."</td>";
    		echo "</tr>";
    		$count++;
  	}
  }

  if($count == 0)
  {
        echo "<tr><td colspan='3.'>You have no pending movies.</td></tr>";
  }
echo "</table></div></div>";

$ret = oci_execute($stid);

//DISPLAY ACCEPTED MOVIES  

//set up divs
echo "<div class='post'><h1 class='title'><a href='#'>My Accepted Movies</a></h1><br /><div class='entry'>";

//set up table
echo "<table width='90%'><tr><th>Movie ID</th><th>Title</th><th>Accept Date</th></tr>";
$count = 0;
while(($row = oci_fetch_array($stid, OCI_ASSOC)))
  {
	if($row['PENDSTATUS']=="0")
    	{
		// add row to the table
		echo "<tr>";
		echo "<td>".$row['MOVID']."</td>";
    		echo "<td>".$row['MOVTITLE']."</td>";
    		echo "<td>".$row['DATEACCEPTED']."</td>";
    		echo "</tr>";
    	}
	$count++;
  }

  if($count == 0)
  {
        echo "<tr><td colspan='3.'>You have no accepted movies.</td></tr>";
  }
echo "</table></div></div>";

$ret = oci_execute($stid);

//DISPLAY REJECTED MOVIES

//set up divs
echo "<div class='post'><h1 class='title'><a href='#'>My Rejected Movies</a></h1><br /><div class='entry'>";

//set up table
echo "<table width='90%'><tr><th>Movie ID</th><th>Title</th><th>Reject Date</th></tr>";
$count = 0;
while(($row = oci_fetch_array($stid, OCI_ASSOC)))
  {
        if($row['PENDSTATUS']=="3")
        {    
                // add row to the table
                echo "<tr>";
                echo "<td>".$row['MOVID']."</td>";
                echo "<td>".$row['MOVTITLE']."</td>";
                echo "<td>".$row['DATEACCEPTED']."</td>";
                echo "</tr>";
        }
        $count++;
  }

  if($count == 0)
  {
        echo "<tr><td colspan='3.'>You have no rejected movies.</td></tr>";
  }
echo "</table></div></div></div>";


include('footer.php');
?>
